<?php namespace App\Core\Repository\Criterias\Permissions;

use App\Core\Repository\Criteria;
use App\Core\Repository\Repository;
use Auth;

class MatchUserCritria extends Criteria{
    
    protected $field;
    protected $loginUser;
    
    public function __construct($field = 'user_id') {
        $this->field = $field;
        $this->loginUser = Auth::user();
    }

    public function apply(Repository $repository){
        parent::apply($repository);
        $this->query->where($this->formatField($this->model, $this->field), '=', $this->loginUser->user_id);
    }
}